package ca.unbc.cpsc672;

import java.io.IOException;

import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

public class Yelp extends ApplicationWindow {

	/**
	 * @param parentShell
	 */
	public Yelp(Shell parentShell) {
		super(parentShell);
	}

	protected Control createContents(Composite parent) {
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new GridLayout(2, true));

		try {
			createButton(composite, "FuzzySet.jpg", "Work on Fuzzy Set",
					new FuzzySetDialog(getShell()));
			createButton(composite, "FuzzyRules.png", "Work on Fuzzy Rules",
					new FuzzyRuleDialog(getShell()));
			WizardDialog window = new WizardDialog(new Shell(),
					new RestaurantRecommendationsWizard());
			window.setMinimumPageSize(1000, 800);
			createButton(composite, "yelp.png", "Recommandations", window);
			createButton(composite, "reset.jpg", "Reset To Default",
					new ResetDialog(getShell()));
		} catch (IOException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}

		return super.createContents(parent);
	}

	private void createButton(Composite composite, String imgName,
			String btnName, final Window window) {
		Button btn = new Button(composite, SWT.NONE);
		Image img = new Image(composite.getDisplay(),
				Yelp.class.getResourceAsStream(imgName));
		btn.setLayoutData(GUIUtils.buildGridData());
		btn.setImage(img);
		btn.setText(btnName);
		btn.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				window.setBlockOnOpen(true);
				window.open();
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {

			}

		});
	}

	public static void main(String[] args) {
		ApplicationWindow window = new Yelp(null);
		window.setBlockOnOpen(true);
		window.open();
	}
}